package com.dukk.espark.core;

import com.alibaba.fastjson.JSONObject;
import com.dukk.espark.utils.ConfigKit;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.SQLContext;
import org.apache.spark.sql.SparkSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * spark计算基础类
 *
 * @version 2020-08-05
 * @author shengshi_feiyang@yeah.net
 *
 */
public abstract class SparkBase implements Serializable {
    private static final long serialVersionUID = 348881889531224362L;

    private static final Logger logger = LoggerFactory.getLogger(SparkBase.class);

    protected ConfigKit configKit;

    protected SparkSession sparkSession;

    protected SQLContext sqlContext;

    protected static JavaSparkContext javaSparkContext;

    protected DbFactory dbFactory;



    public void setConfigKit(ConfigKit configKit) {
        this.configKit = configKit;
    }

    public void setSparkSession(SparkSession sparkSession) {
        this.sparkSession = sparkSession;
    }

    public void setDbFactory(DbFactory dbFactory) {
        this.dbFactory = dbFactory;
    }

    public void setSqlContext(SQLContext sqlContext) {
        this.sqlContext = sqlContext;
    }

    public void setJavaSparkContext(JavaSparkContext javaSparkContext) {
        this.javaSparkContext = javaSparkContext;
    }


    /**
     * 继承类必须实现此方法,业务算法入口类
     *
     * @param params 脚本里面传入的自定义参数
     */
    public abstract  void doAi(JSONObject params);

}
